<template>
  <view class="page">
   
    <view class="assess-page">
      <view style="padding: 12px" v-if="detailInfo[0].companyName">
        <!-- 企业名称 -->
        <view class="top-title">
          <img class="top-img" src="@/static/market/levelAssessTitle.png" />
          <span class="top-text">{{ detailInfo[0].companyName }}</span>
        </view>
        <!-- 历史信用评定详情区域 -->
        <view class="main-content" v-for="(item ,index) of detailInfo" :key="index">
          <!-- 检查日期 -->
          <view class="content-title flex jc-sb">
            <view class="w-28">{{ moment(item.changeDate).format('YYYY年MM月DD日') }}</view>
            <view class="w-34">信用等级：{{ item.beforeCreditLevel + '➡' + item.afterCreditLevel }}</view>
            <view class="w-40">信用积分：{{ item.beforeCreditScore + '➡' + item.afterCreditScore }}</view>
          </view>
          <view class="content-body" v-for="itemc of item.creditInspireMainItemVOList" :key="itemc.inspireMainUuid">
            <view class="body-title flex">
              <view>信用评定人：{{ itemc.operatorName }}</view>
              <view class="ml-16">时间：{{ itemc.operatorDate }}</view>
            </view>
            <view class="flex jc-sb ai-c" v-for="items of itemc.standardList" :key="items.standardUuid">
              <view class="body-left">{{ items.standardName }}</view>
              <view class="body-right">{{ items.addScore }}</view>
            </view>
          </view>
        </view>
      </view>
      <view v-else  class="card card-content"  style="display:flex;justify-content:center;padding: 12px">暂无数据~</view>
    </view>
    <!-- <view style="position: absolute;top: 50%;left: 45%;">
      <u-loading :show="isLoading" mode="circle" size="80"></u-loading>
    </view> -->
  </view>
</template>

<script>
import moment from 'moment'
import checkService from "@/service/check/check.service.js";
export default {
  onLoad (opt) {
    // this.retailerUuid = opt.retailerUuid
  },
  props:{
		retailerUuid:{
      type: String,
			default: ''
    }
	},
  mounted () {
    this.getHisDetailData()
  },
  data() {
    return {
      moment,
      // isLoading: false,
      // retailerUuid: '',
      detailInfo: [
        {
        companyName: '', // 企业名称
        changeDate: '0000-00-00', // 检查日期
        beforeCreditLevel: '-', // 信用等级start
        afterCreditLevel: '-', // 信用等级end
        beforeCreditScore: '-', // 信用积分start
        afterCreditScore: '-', // 信用积分end
        creditInspireMainItemVOList: [] // 评定人整合
      }
      ],
    };
  },
  methods: {
    getHisDetailData () {
      // this.isLoading = true
      this.$modal.showLoading("请稍后...");
      checkService.getCreditHisInspireRecord({ retailerUuid: this.retailerUuid }).then(res => {
        if (res.code == '200' && res.bean.length) {
          this.detailInfo = []
          res.bean.forEach(v => {
            this.detailInfo.push({
              companyName: v?.companyName || '-', // 企业名称
              changeDate: v?.changeDate || '-', // 检查日期
              beforeCreditLevel: v?.beforeCreditLevel || '-', // 信用等级start
              afterCreditLevel: v?.afterCreditLevel || '-', // 信用等级end
              beforeCreditScore: v?.beforeCreditScore || '-', // 信用积分start
              afterCreditScore: v?.afterCreditScore || '-', // 信用积分end
              creditInspireMainItemVOList: this.reCombineCommit(v.creditInspireMainItemVOList) || [] // 评定人整合
            })
          })
        }
        this.$modal.hideLoading();
        // this.isLoading = false
      }).catch(err => {
        this.$modal.hideLoading();
        // this.isLoading = false
        console.log(err)
      }).finally(() => {
        console.log(this.detailInfo, 'data for page assembly')
      })
    },
    // 重组返回数据（对应评定人意见得分归类）
    reCombineCommit (list) {
      let _arr = []
      list.forEach(v => {
        if (_arr.length) {
          _arr.forEach(o => {
            if (o.inspireMainUuid === v.inspireMainUuid) {
              // 对应评定人下的意见进行分类
              if (o.standardList.some(i => i.standardUuid !== v.standardUuid)) {
                o.standardList.push({
                  standardName: v.standardName,
                  standardUuid: v.standardUuid,
                  addScore: v.addScore
                })
              }
            } else {
              _arr.push({
                operatorName: v.operatorName, // 信用评定人
                operatorDate: v.operatorDate, // 信用评定时间
                inspireMainUuid: v.inspireMainUuid, // mainId
                standardList: [{
                  standardName: v.standardName,
                  standardUuid: v.standardUuid,
                  addScore: v.addScore
                }]
              })
            }
          })
        } else {
          _arr.push({
            operatorName: v.operatorName, // 信用评定人
            operatorDate: v.operatorDate, // 信用评定时间
            inspireMainUuid: v.inspireMainUuid, // mainId
            standardList: [{
              standardName: v.standardName,
              standardUuid: v.standardUuid,
              addScore: v.addScore
            }]
          })
        }
      })
      console.log(_arr)
      return _arr
    }
  }
};
</script>

<style lang="scss" scoped>
.page {
  padding: 0;
  .top-title {
    display: flex;
    justify-content: center;
    align-items: center;
    .top-img {
      width: 32px;
      height: 32px;
    }
    .top-text {
      font-size: 38rpx;
      font-weight: 700;
      margin-left: 15px;
      color: #2980e3;
    }
  }
  .main-content {
    margin-top: 12px;
    width: 100%;
    border: 1px solid #eee;
    border-radius: 10px;
    box-shadow: 0px 1px 5px #d9d6d6;
    .content-title {
      height: 70rpx;
      padding: 20rpx 20rpx;
      color: #2980e3;
      font-size: 20rpx;
      font-weight: 500;
    }
    .content-body {
      height: auto;
      line-height: 70rpx;
      padding: 0 28rpx;
      background: #fafafa;
      color: #868686;
      font-size: 24rpx;
      font-weight: 500;
      border-top: 2px solid #eee;
      .body-title {
        color: #2980e3;
        font-size: 24rpx;
      }
      .body-left {
        width: 95%;
      }
      .body-right {
        width: 5%;
      }
    }
  }
}
.w-28 {
  width: 28%;
}
.w-34 {
  width: 34%;
}
.w-40 {
  width: 40%;
}
.flex {
  display: flex;
}
.jc-sb {
  justify-content: space-between;
}
.ai-c {
  align-items: center;
}
.ml-16 {
  margin-left: 34rpx;
}
</style>